package p.ithorns.integration.zk.id;

import lombok.Data;

import java.io.Serializable;
import java.util.Objects;

/**
 * IdBean
 *
 * @author ithorns
 * @version 1.0
 * @date 2021/9/7 20:56
 */
@Data
public class IdBean implements Serializable {

    public final static String ID_SEPARATOR = "_";

    /**
     * 组
     */
    private String group;
    /**
     * 应用
     */
    private String app;
    /**
     * 模块
     */
    private String module;

    /**
     * 业务
     */
    private String biz;

    private String path;

    private IdBean(final String path) {
        this.path = path;
    }

    public String getPath() {
        return path;
    }

    public static IdBean.IdBeanBuilder builder() {
        return new IdBean.IdBeanBuilder();
    }

    public static class IdBeanBuilder {
        private final StringBuilder path;

        IdBeanBuilder() {
            path = new StringBuilder();
        }

        public IdBean.IdBeanBuilder group(final String group) {
            if (Objects.nonNull(group)) {
                path.append("/").append(group);
            }
            return this;
        }

        public IdBean.IdBeanBuilder app(final String app) {
            if (Objects.nonNull(app)) {
                path.append("/").append(app);
            }
            return this;
        }

        public IdBean.IdBeanBuilder module(final String module) {
            if (Objects.nonNull(module)) {
                path.append("/").append(module);
            }

            return this;
        }

        public IdBean.IdBeanBuilder biz(final String biz) {
            if (Objects.nonNull(biz)) {
                path.append("/").append(biz);
            }
            return this;
        }

        public IdBean build() {
            //path.append(ID_SEPARATOR);
            return new IdBean(path.toString());
        }
    }
}
